package com.jin.工厂模式.简单工厂模式.顺从.service.Impl;

import com.alibaba.fastjson.JSON;
import com.jin.工厂模式.简单工厂模式.违背.coupon.CouponResult;
import com.jin.工厂模式.简单工厂模式.违背.coupon.CouponService;
import com.jin.工厂模式.简单工厂模式.顺从.service.ICommodity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

public class CouponCommodityService implements ICommodity {
    private Logger logger = LoggerFactory.getLogger(CouponCommodityService.class);
    private CouponService couponService = new CouponService();
    @Override
    public void sendCommodity(String uid, String commodityId, String bizId, Map<String, String> extMap) throws Exception {
        CouponResult couponResult = couponService.sendCoupon(uid, commodityId, bizId);
        logger.info("请求参数优惠券=> uid:{} commodityId:{} bizId:{} extMap:{}", uid,commodityId,bizId, JSON.toJSON(extMap));
        logger.info("测试结果优惠券:{}",JSON.toJSON(couponResult));
        if (!"0000".equals(couponResult.getCode()))
            throw new RuntimeException();
    }
}
